<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <meta http-equiv='X-UA-Compatible' content='ie=edge'>
    <title>Document</title>
</head>

<body>
    <div id='app'>
        <div>id: <input type="text" v-model="id"></div>
        <div>name: <input type="text" v-model="name"><button @click="add">新增</button></div>
        <hr>
        <ul>
            <!-- Vue中有diff算法,更新较少变动的节点 -->
            <li v-for="(item,index) in arr" :key="item.id">
                <input type="checkbox">
                <span>{{item.name}}</span>
            </li>
        </ul>
    </div>
    <script src='../js/vue.js'></script>
    <script>
        const vm = new Vue({
            el: '#app',
            data: {
                id: '',
                name: '',
                arr: [{
                    id: 1,
                    name: '老大'
                },
                {
                    id: 2,
                    name: '老二'
                },
                {
                    id: 3,
                    name: '老三'
                }],
            },
            methods: {
                add() {
                    this.arr.unshift({ id: this.id, name: this.name })
                }
            },
        })
    </script>
</body>

</html>